package org.geemp.game.gm.service;

import org.apache.ibatis.annotations.Param;
import org.geemp.game.gm.mapper.GameMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author JackRen
 * @date 2021-04-27 13:31
 * @description:
 */
@Service
public class GameDBServiceImpl {

    @Autowired
    private GameMapper gameMapper;
    
    public List<Map<String,Object>> obtainDataBy(String CT_USERID, String CT_NAME){
        List<Map<String,Object>> dataList= gameMapper.obtainDataBy(CT_USERID,CT_NAME);
        return dataList;
    }

    public Map<String,Object> obtainChartIndexBy(String CT_USERID, String CT_NAME){
        Map<String,Object> dataList= gameMapper.obtainChartIndexBy(CT_USERID,CT_NAME);
        return dataList;
    }

    public Map<String,Object> obtainITEMIDXBy(String IT_USERIDX, String IT_SLOTTYPE){
        Map<String,Object> dataList= gameMapper.obtainITEMIDXBy(IT_USERIDX,IT_SLOTTYPE);
        return dataList;
    }

    public int updateItemInfoByID(int IT_SEQ, int IT_OPTIONID1,int IT_OPTIONVALUE1,
                                  int IT_OPTIONID2, int IT_OPTIONVALUE2,
                                  int IT_OPTIONID3, int IT_OPTIONVALUE3,
                                  int IT_OPTIONID4, int IT_OPTIONVALUE4,
                                  int IT_OPTIONID5, int IT_OPTIONVALUE5,
                                  int IT_OPTIONID6, int IT_OPTIONVALUE6,
                                  int IT_OPTIONID7, int IT_OPTIONVALUE7) {
        int ret = gameMapper.updateItemInfoByID(IT_SEQ,IT_OPTIONID1,IT_OPTIONVALUE1,IT_OPTIONID2,IT_OPTIONVALUE2,
                IT_OPTIONID3,IT_OPTIONVALUE3,IT_OPTIONID4,IT_OPTIONVALUE4,IT_OPTIONID5,IT_OPTIONVALUE5,
                IT_OPTIONID6,IT_OPTIONVALUE6,IT_OPTIONID7,IT_OPTIONVALUE7);
        return ret;
    }


    /*
     * 根据前端传入类型获取数据
     * @author JackRen
     * @date 2021/12/6
     * @return
     **/
    public List<Map<String,Object>> obtainUpGradeCharInfoMaps(String type) {
        List<Map<String,Object>> maps = new ArrayList<>();
        if ("1".equals(type)) {
            maps = gameMapper.obtainUpGradeCharInfo();
        }else if ("2".equals(type)) {
            maps = gameMapper.obtainUpGradeChar1Info();
        }else {
            maps = gameMapper.obtainUpGradeCharInfo();
        }
        return maps;
    }


    /*
     * 获取到IT_USERIDX
     * @author JackRen
     * @date 2021/12/6
     * @return
     **/
    public int obtainInventoryIndex(int IT_SEQ) {
        return gameMapper.obtainInventoryIndex(IT_SEQ);
    }

    public int updateCTChartInfo(int IT_SEQ, int CT_GOLD,String CT_USERID){
        int IT_USERIDX=obtainInventoryIndex(IT_SEQ);
        Map<String,Object> map= obtainChartTableInfoByConfig(IT_USERIDX,CT_USERID);
        if (map==null) {
            return 0;
        }
        int dbGold = Integer.valueOf(String.valueOf(map.get("CT_GOLD")));
        if (dbGold < CT_GOLD) {
            return -1;
        }
        int updateDbGold = dbGold-CT_GOLD;
        int CT_SEQ = Integer.valueOf(String.valueOf(map.get("CT_SEQ")));
        return gameMapper.updateCTChartInfo(updateDbGold,CT_SEQ);
    }

    private Map<String,Object> obtainChartTableInfoByConfig(int CT_CHARINDEX,String CT_USERID) {
        return gameMapper.obtainCharGoldIndex(CT_CHARINDEX,CT_USERID);
    }

}
